//
//  DiaryFirstTableViewCell.m
//  土巴兔
//
//  Created by 千锋 on 16/1/4.
//  Copyright (c) 2016年 IOS1503薛凯. All rights reserved.
//

#import "DiaryFirstTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Default.h"
@implementation DiaryFirstTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    return self;
}
- (void)createUI{
    //背景图片
    _imageview=[[UIImageView alloc] initWithFrame:CGRectMake(10, 0, DEVICEWIDTH-20, 140)];
    _imageview.layer.cornerRadius=8;
    _imageview.clipsToBounds=YES;
    [self.contentView addSubview:_imageview];
    //主标题
    _title=[[UILabel alloc] initWithFrame:CGRectMake(15, 5, 300, 30)];
    _title.textColor=[UIColor whiteColor];
    _title.font=[UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:_title];
    //副标题
    _subTitle=[[UILabel alloc] initWithFrame:CGRectMake(15, 35, self.contentView.bounds.size.width-100, 15)];
    _subTitle.font=[UIFont systemFontOfSize:13];
    _subTitle.textColor=[UIColor whiteColor];
    [self.contentView addSubview:_subTitle];
    //个人头像
    _header=[[UIImageView alloc] initWithFrame:CGRectMake(20, 98, 36, 36)];
    _header.layer.cornerRadius=18;
    _header.layer.borderWidth=1;
    _header.layer.borderColor=[UIColor whiteColor].CGColor;
    _header.clipsToBounds=YES;
    [self.contentView addSubview:_header];
    //阅读次数
    _saw=[[UIButton alloc] initWithFrame:CGRectMake(self.contentView.bounds.size.width-150, 120, 80, 13)];
    _saw.titleLabel.font=[UIFont systemFontOfSize:13];
    [_saw setImage:[UIImage imageNamed:@"ico_guanzhu_gray"] forState:UIControlStateNormal];
    _saw.imageEdgeInsets=UIEdgeInsetsMake(0, -10, 0, 0);
    [self.contentView addSubview:_saw];
    //评论次数
    _comment=[[UIButton alloc] initWithFrame:CGRectMake(self.contentView.bounds.size.width-100, 120, 105, 13)];
    _comment.titleLabel.font=[UIFont systemFontOfSize:13];
    [_comment setImage:[UIImage imageNamed:@"ico_common_line"] forState:UIControlStateNormal];
    _comment.imageEdgeInsets=UIEdgeInsetsMake(0, -10, 0, 0);
    [self.contentView addSubview:_comment];
}
- (void)relayoutWithModel:(DiaryModel*)model{
    [_imageview sd_setImageWithURL:[NSURL URLWithString:model.cover_image]];
    NSLog(@"%@",model.cover_image);
    [_title setText:model.name];
    [_subTitle setText:[NSString stringWithFormat:@"%.1f万/%3.0dM2/%@",model.product_price/10000,model.area/10000000,model.house_type_name]];
    [_header sd_setImageWithURL:[NSURL URLWithString:model.owner_avatar]];
    [_saw setTitle:[NSString stringWithFormat:@"%0.5d",model.view_num/1000000] forState:UIControlStateNormal];
    [_comment setTitle:[NSString stringWithFormat:@"%0.4d",model.comment_number/1000000] forState:UIControlStateNormal];
}
@end
